<template>
    <div class="main">
        <div class="title-box">
            <Titile desc="成就" @clickMore="clickMore" />
        </div>
        <el-empty description="暂无数据" :image-size="200" v-if="!state.list.length" />
        <div class="detail dispaly-between" v-if="state.list.length">
            <div class="right">
                <div class="pointer" @click="clickItemSkipDetail(state.list[0])">
                    <div class="title-one over-1">{{ state.list[0].title }}</div>
                    <div class="title-two">{{ state.list[0].title }}</div>
                </div>
                <div class="list">
                    <div @click="clickItemSkipDetail(item)" class="item dispaly-just-between pointer"
                        v-for="(item, index) in state.list" :key="index">
                        <div class="left dispaly-center">
                            <div class="left-logo dispaly-center">
                                <img src="/src/assets/image/s-logo.png">
                            </div>
                            <div class="title over-1">{{ item.title }}</div>
                        </div>
                        <div class="right">{{ item.createTime }}</div>
                    </div>
                </div>
            </div>
            <div class="cover pointer" @click="clickItemSkipDetail(state.list[0])">
                <div class="cover-box">
                    <img :src="state.list[0].img">
                    <div class="tip">{{ state.list[0].title }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import Titile from '@/components/title.vue'
import { reactive, onMounted } from 'vue'
import { getIndexArticle } from '@/api/index/index'
import { useRouter } from 'vue-router';

const state = reactive({
    list: [],
    loading: true
})

// 首页推荐
const getIndexArticleData = async () => {
    const res = await getIndexArticle({ type: 4, limit: 5 })
    if (res.code == 200) {
        state.list = res.data
    }
    state.loading = false
}

onMounted(() => {
    getIndexArticleData()
})

// 点击更多
const router = useRouter()
const clickMore = () => {
    localStorage.setItem('tabIndex', 2)
    router.push({
        path: '/achievements'
    })
}

// 跳转详情
const clickItemSkipDetail = (item) => {
    router.push({
        path: '/detail',
        query: { id: item.id, type: 'achievement', tValue: item.type }
    })
}
</script>

<style lang="scss" scoped>
.main {


    .detail {
        padding: 25px 0 0 0;

        .cover {
            margin-left: 40px;

            .cover-box {
                position: relative;
                width: 379px;
                height: 249px;
                border-radius: 10px;

                .tip {
                    background: rgba($color: #000000, $alpha: .5);
                    border-radius: 10px;
                    color: #fff;
                    padding: 20px;
                    font-family: MicrosoftYaHei;
                    font-size: 14px;
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    right: 0;
                }

                img {
                    width: 379px;
                    height: 249px;
                    border-radius: 10px;
                }

            }

        }

        .right {
            max-height: 249px;
            width: 100%;

            .title-one {
                color: $primary-color;
                font-family: MicrosoftYaHei, MicrosoftYaHei;
                font-weight: bold;
                font-size: 18px;
                margin-bottom: 19px;
            }

            .title-two {
                font-family: MicrosoftYaHei;
                font-size: 14px;
                color: #666666;
            }

            .list {
                overflow: scroll;
                margin-top: 20px;
                max-height: 163px;
                border-top: 1px dashed #ccc;
                padding-top: 19px;



                .item {
                    width: 100%;

                    .left {
                        flex: 1;

                        .left-logo {
                            margin-right: 8px;

                            img {
                                width: 12px;
                                height: 12px;
                            }
                        }

                        .title:hover {
                            color: $primary-color;
                        }

                        .title {
                            font-family: MicrosoftYaHei;
                            font-size: 14px;
                            color: #222222;
                        }
                    }

                    .right {
                        flex: 1;
                        font-family: MicrosoftYaHei;
                        font-size: 14px;
                        color: #999999;
                    }
                }
            }
        }
    }
}
</style>